package com.azy.controller;

import com.azy.pojo.entity.Products;
import com.azy.pojo.vo.ProductsVo;
import com.azy.service.ProductsService;
import com.azy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ fileName:ProductsController
 * @ description:
 * @ author:Azy
 * @ createTime:2023/4/12 19:21
 * @ version:1.0.0
 */
@RestController
@RequestMapping("products")
@Api(tags = "商品操作api")
public class ProductsController {
   @Autowired
    private ProductsService productsService;
    @PostMapping("/list/{current}/{pageSize}")
    @ApiOperation(value = "根据条件分页查询商品信息")
    public Result list(
            @ApiParam(value = "当前页面",name = "current",required = true,defaultValue = "1")
            @PathVariable Integer current,
            @ApiParam(value = "每页条数",name = "pageSize",required = true,defaultValue = "5")
            @PathVariable Integer pageSize,
            @RequestBody ProductsVo productsVo
            ){
        return productsService.findByPage(current,pageSize,productsVo);
    }
    @GetMapping("selectById/{pid}")
    @ApiOperation(value = "根据id查询单个商品")
    public Result queryById(@PathVariable  String pid){
        return productsService.findById(pid);
    }
    @DeleteMapping("deleteById/{pid}")
    @ApiOperation(value = "根据id删除")
    public Result deletById(@PathVariable  String pid){
        return productsService.deleteById(pid);
    }
    @PostMapping("insert")
    @ApiOperation(value = "新增单条数据")
    public Result insert(Products products){
        return productsService.insert(products);
    }
    @PutMapping("update")
    @ApiOperation(value = "根据id修改")
    public Result update(Products products){
        return productsService.update(products);
    }
}
